package com.schoolET.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolET.entity.Chat;
import com.schoolET.mapper.ChatMapper;
import com.schoolET.service.IChatService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户之间的聊天内容 服务实现类
 * </p>
 *
 * @author le
 * @since 2024-06-04
 */
@Service
public class ChatServiceImpl extends ServiceImpl<ChatMapper, Chat> implements IChatService {

    @Override
    public Page<Chat> findChat(String position, String nickname, Integer pageNum, Integer pageSize) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (position != null && !position.isEmpty()){
            queryWrapper.eq("r.position", position);
        }
        if (nickname != null && !nickname.isEmpty()){
            queryWrapper.like("w.nick_name", nickname);
        }
        queryWrapper.eq("c.flag",0);
        queryWrapper.eq("w.flag",0);
        queryWrapper.eq("r.flag",0);
        Page<Chat> page = new Page<>(pageNum, pageSize);
        baseMapper.selectChatPage(page, queryWrapper);
        return page;
    }
}
